package com.xiaotu.spider.pipeline;

import java.util.List;

import org.springframework.stereotype.Component;

import com.xiaotu.common.model.TVDanMuCommentModel;
import com.xiaotu.common.util.Constants;
import com.xiaotu.common.util.DataRedisKeyUtils;
import com.xiaotu.spider.APipeline;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;

/**
 * 弹幕数据存储
 * @author wangyanlong
 * @date 2019年7月16日 下午5:02:51
 *
 */
@Component("PlatformDanMuPipeline")
public class PlatformDanMuPipeline extends APipeline {

	@Override
	protected void doProcess(ResultItems resultItems, Task task) {
		
		List<TVDanMuCommentModel> list = resultItems.get(TVDanMuCommentModel.class.getName());
        if(null != list && list.size()>0){
        	String key = DataRedisKeyUtils.getKey(Constants.DataRedisKey.TV_DANMU_YYYYMMDD);
        	for(int i=0;i<list.size();i++){
        		cacheHandler.hSet(key, list.get(i).getTvName()+"_"+System.currentTimeMillis()+i, list.get(i));
        	}
        	cacheHandler.setCacheTimeout(key);
        }
		/*TVDanMuCommentModel tv = resultItems.get(TVDanMuCommentModel.class.getName());
	        if (tv == null)
	            return;
	        String key = DataRedisKeyUtils.getKey(Constants.DataRedisKey.TV_DANMU_YYYYMMDD);
	        cacheHandler.hSet(key, tv.getTvId()+"_"+tv.getCommentId(), tv);
	        cacheHandler.setCacheTimeout(key);*/
	}
}
